﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using GSdk.Net.Lglcd;
using System.Windows;
using System.Windows.Markup;
using System.Xaml;
using GSdk.Shared.Windows.Properties;

namespace GSdk.Shared.Windows
{
    public class Control : DependencyObject, IDisposable
    {
        private volatile bool m_Disposing;

        public Control()
        {
            /*Font = new Font(
                "monospace",
                12.0f,
                System.Drawing.FontStyle.Bold
            );*/
        }

        public static Property<Font> FontProperty = new Property<ContentControl, Font>(c => c.Font, new FrameworkPropertyMetadata(new Font("monospace", 12.0f, System.Drawing.FontStyle.Bold), FrameworkPropertyMetadataOptions.Inherits));
        public static Property<int> WidthProperty = new Property<ContentControl, int>(c => c.Width, new FrameworkPropertyMetadata(1, FrameworkPropertyMetadataOptions.Inherits));
        public static Property<int> HeightProperty = new Property<ContentControl, int>(c => c.Height, new FrameworkPropertyMetadata(1, FrameworkPropertyMetadataOptions.Inherits));

        public Font Font
        {
            get { return FontProperty[this]; }
            set
            {
                if (Font != null && Font != value)
                    Font.Dispose();
                FontProperty[this] = value;
            }
        }
        public int Width { get { return WidthProperty[this]; } set { WidthProperty[this] = value; } }
        public int Height { get { return HeightProperty[this]; } set { HeightProperty[this] = value; } }
        public virtual DeviceTypes DeviceType { get { return DeviceTypes.Invalid; } }
        public bool Disposing { get { return m_Disposing; } protected set { m_Disposing = value; } }

        #region Dispose handling
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            Disposing = true;
            if (disposing)
            {
                // Managed resources
            }

            // Unmanaged resources
            try
            {
                if (Font != null) Font.Dispose();
            }
            catch { }
        }

        ~Control()
        {
            Dispose(false);
        }
        #endregion
    }
}
